package com.adtech.adms.system.pojo;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.json.annotations.JSON;

import com.adtech.adms.commons.tree.TreeNode;

/**
 * 系统用户
 * 系统用户模型
 * @author Dormin 
 * @since 2011-8-11 
 * 
 * @Copyright (C) AD Tech Workshop All Right Reserved
 */
public class User implements java.io.Serializable {

	private static final long serialVersionUID = -502508173422034310L;
	public static final byte TYPE_SYSTEM = 1;
	public static final byte TYPE_EIP = TYPE_SYSTEM << 1;
	public static final byte TYPE_VPN = TYPE_SYSTEM << 2;
	public static final byte[] TYPE_ARRAY = { TYPE_SYSTEM, TYPE_EIP, TYPE_VPN };
	private Integer userId;

	private String loginName;
	private String password;
	private String userName;


	private String address;
	private String qq;
	private String email;
	private String mobile;
	private String phone;
	private String msn;
	private String note;
	private String inoffice;



	private String sessionId;
	private Date lastLoginTime;
	private Date createTime;
	private Date editTime;


	private Byte loginType=0;
	private Byte[] loginTypes;
	private String roleNames="";
	private String roleIds;
	private String topoIds;


	/**
	 * 每次登录后记录用户当前ip，不保存至数据库
	 */
	private String loginIp;





	private List<Role> roles = new ArrayList<Role>();
	
	private List<TreeNode<Feature>> featuresTree = new ArrayList<TreeNode<Feature>>();
	private List<Topo> topos = new ArrayList<Topo>();
	
	private String isDelete = "0";
	
	// 不映射到数据库
	private String isLogout = "0";
	private final static Map<String,String> sheetMap = new HashMap<String,String>();


	
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Byte getLoginType() {
		return loginType;
	}

	public void setLoginType(Byte loginType) {
		this.loginType = loginType;
	}




	@JSON(serialize = false)
	public List<TreeNode<Feature>> getFeaturesTree() {
		return featuresTree;
	}

	public void setFeaturesTree(List<TreeNode<Feature>> featuresTree) {
		this.featuresTree = featuresTree;
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getQq() {
		return qq;
	}

	public void setQq(String qq) {
		this.qq = qq;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getMsn() {
		return msn;
	}

	public void setMsn(String msn) {
		this.msn = msn;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public String getInoffice() {
		return inoffice;
	}

	public void setInoffice(String inoffice) {
		this.inoffice = inoffice;
	}



	public String getIsDelete() {
		return isDelete;
	}

	public void setIsDelete(String isDelete) {
		this.isDelete = isDelete;
	}

	@JSON(serialize=false)
	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}



	@JSON(serialize=false)
	public String getSessionId() {
		return sessionId;
	}

	public void setSessionId(String sessionId) {
		this.sessionId = sessionId;
	}

	public Date getLastLoginTime() {
		return lastLoginTime;
	}

	public void setLastLoginTime(Date lastLoginTime) {
		this.lastLoginTime = lastLoginTime;
	}

	public String getLoginIp() {
		return loginIp;
	}

	public void setLoginIp(String loginIp) {
		this.loginIp = loginIp;
	}

	@JSON(serialize=false)
	public List<String> getLoginTypeValues() {
		List<String> types = new ArrayList<String>();
		int max = TYPE_ARRAY.length;
		for (int i = 0; i < max; i++) {
			if ((loginType.byteValue() & TYPE_ARRAY[i]) == TYPE_ARRAY[i]) {
				types.add(new Byte(TYPE_ARRAY[i]).toString());
			}
		}
		return types;
	}
	@JSON(serialize=false)
	public Byte[] getLoginTypes() {
		return loginTypes;
	}

	public void setLoginTypes(Byte[] loginTypes) {
		this.loginTypes = loginTypes;
		if (loginTypes != null) {
			for (Byte loginType2 : loginTypes) {
				setLoginType(new Integer(loginType.byteValue() | loginType2.byteValue()).byteValue());
			}
		}
	}
	public String getRoleNames() {
		StringBuilder builder=new StringBuilder();
		for (Role role : roles) {
			builder.append( role.getRoleName() + " ");
		}
		roleNames=builder.toString();
		return roleNames;
	}

	public void setRoleNames(String roleNames) {
		this.roleNames = roleNames;
	}

	@JSON(serialize = false)
	public String getRoleIds() {
		if(roleIds==null) {
			StringBuilder builder=new StringBuilder();
			for (Role role : roles) {
				builder.append(role.getRoleId());
				if(roles.indexOf(role)<roles.size()-1){
					builder.append(",");
				}
			}
			roleIds=builder.toString();
		}
		return roleIds;
	}

	public void setRoleIds(String roleIds) {
		this.roleIds = roleIds;
	}
	private String[] names;



	public String[] getNames() {
		return names;
	}

	public void setNames(String[] names) {
		this.names = names;
	}
	
	public String getIsLogout() {
		return isLogout;
	}

	public void setIsLogout(String isLogout) {
		this.isLogout = isLogout;
	}

	public Date getEditTime() {
		return editTime;
	}

	public void setEditTime(Date editTime) {
		this.editTime = editTime;
	}

	public List<Topo> getTopos() {
		return topos;
	}

	public void setTopos(List<Topo> topos) {
		this.topos = topos;
	}

	public String getTopoIds() {
		if(topoIds==null) {
			StringBuilder builder=new StringBuilder();
			for (Topo topo : topos) {
				builder.append(topo.getId());
				if(topos.indexOf(topo)<topos.size()-1){
					builder.append(",");
				}
			}
			topoIds=builder.toString();
		}
		return topoIds;
	}

	public void setTopoIds(String topoIds) {
		this.topoIds = topoIds;
	}

	
	
	
	
	
	



}
